import pygame
from abc import abstractmethod, ABCMeta
from typing import Tuple, Callable


# abstract format of UI widget
class BaseWidget(pygame.sprite.Sprite, metaclass=ABCMeta):

    def __init__(
            self,
            display_surface: pygame.Surface,
            groups: Tuple[pygame.sprite.LayeredUpdates, ...],
            on_click_callbacks: Tuple[Callable[[], None], ...] = ()
    ):
        super().__init__(*groups)  # add into groups
        self.is_visible = True
        self.on_click_callbacks = on_click_callbacks
        self.display_surface = display_surface
    
    @abstractmethod
    def undraw(self) -> None:
        pass
    
    def on_click(self) -> None:
        if self.is_visible:
            for callback in self.on_click_callbacks:
                callback()
